<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/3/21
 * Time: 16:28
 */

namespace Home\Controller;


use Think\Controller;

class CommentController extends Controller
{
    //ajax发表评论
    public function add(){
        if(IS_POST)
        {
            $model = D('Admin/Comment');
            if($model->create(I('post.'),1))
            {
                if($id = $model->add())
                {
                    $this->success(array(
                        'id' => $id,
                        'face' => session('face'),
                        'username' => session('m_username'),
                        'addtime' => date('Y-m-d H:i:s'),
                        'content' => I('post.content'),
                        'star' => I('post.star'),
                    ),'',true);
                }
            }
            $this->error($model->getError(),'',true);
        }
    }

    /**ajax回复**/
    public function reply(){
        if(IS_POST){
            $model = D('Admin/CommentReply');
            if($model->create(I('post.'),1)){
                if($model->add()){
                    $this->success(array(
                        'face' => session('face'),
                        'username' => session('m_username'),
                        'addtime' => date('Y-m-d H:i:s'),
                        'content' => I('post.content'),

                    ));
                }
            }
            $this->error($model->getError());
        }
    }

    public function ajaxGetPl(){
        $goodsId = I('get.goods_id');
        $model = D('Admin/Comment');
        $data = $model->search($goodsId,5);
        echo json_encode($data);
    }
}